package cn.lanqiao.demo.controller;

import cn.lanqiao.demo.entity.Notify;
import cn.lanqiao.demo.service.NotifyService;
import com.google.gson.Gson;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("notify")
public class NotifyController {
    @Resource
    private NotifyService notifyService ;

    @GetMapping("/getAll")
    public String getAll(){
        Gson gson = new Gson() ;
        String s = gson.toJson(notifyService.getAll()) ;
        return s ;
    }

    @GetMapping("/getById")
    public Notify getById(int Nno){
        return notifyService.getById(Nno);
    }

    @GetMapping("/add")
    public String add(Notify notify){
        int i = notifyService.add(notify) ;
        if(i > 0){
            return "yes" ;
        }
        else{
            return "no" ;
        }
    }

    @GetMapping("/deleteById")
    public String deleteById(int Nno){
        int i = notifyService.deleteById(Nno) ;
        List list = notifyService.getAll();
        Gson g = new Gson();
        String list1 = g.toJson(list);
        return list1;
    }

    @GetMapping("/update")
    public String update(Notify notify){
        int i = notifyService.update(notify) ;
        if (i > 0){
            return "yes" ;
        }else{
            return "no" ;
        }
    }

}
